package com.heiye.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heiye.pojo.College;
import com.heiye.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class CollegeController {
    @Autowired
    private CollegeService collegeService;

    //通过学院id获取到学院的信息
    @GetMapping("/selectCollegeByCId")
    @ResponseBody
    public College selectCollegeByCId(@RequestParam("cId") int cId) {
        QueryWrapper<College> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("college_id", cId);
        College college = new College();
        college = collegeService.getOne(queryWrapper);
        return college;
    }

    //获取所有学院信息
    @GetMapping("/selectAllCollege")
    @ResponseBody
    public List<College> selectAllCollege() {
        List<College> list = collegeService.list();
        for(College c:list){
            System.out.println(c.toString());
        }
        return list;
    }
}
